"""
定义：
    被定义在{}中的数据，以Key-value键值对存储
    键key必须是唯一的在字典中
    可变的数据类型：字典、列表
"""
data = {"host":
            {"admin":
                 {"user1":"root","user2":"jerry","user3":"use"},
             "IP":
                 {"ip_host":"1.1.2.1","ip_mysql":"1.1.2.2","ip_system":"1.1.2.3"}
            }
        }
host_name = data.get("host")
IP_address = host_name.get("IP").get("ip_host")
print(IP_address)
user_name = host_name.get("admin")

data_01 = {"nginx":"1.18","redis":"1.11","Docker":"1.11"}
data_02 = {"192.168.7.1":["root","DD.08.dd","22"],"10.11.0.2":["admin","DD.08.dd","22"]}
print(type(data_02))

print("--------------------字典的增删改查---------------------")
#添加数据
data_01["redis"] = "5.5"
print(data_01)
# 修改数据
data_01["nginx"] = "1.1"
print(data_01)

# 获取数据 从字典里取数据，靠key取
#如果键要写错了，程序会直接报错，会直接暂停接下来代码的运行
docker_version = data_01["Docker"]
print(docker_version)

#获取数据建议使用：字典.get(key)方法
#如果键写错了，程序不会报错，会返回一个none,不会妨碍接下来代码的运行
redis_version = data_01.get("redis")
if redis_version:
    print(redis_version)
else:
    print("无数据")
print("----------------------------字典对象的操作方法--------------------")
#字典的.keys()方法：返回字典里所有的键
#以列表的形式返回字典中所有的键
# print(data_01.keys())
# new_software = input("软件名称：").strip()
# if new_software in data_01.keys():
#     print("存在")
#     print("软件名：%s,版本: %s" % (new_software,data_01.get(new_software)))
# else:
#     print("不存在")

#items()方法主要做字典的遍历
for app_name, app_version in data_01.items():
    print("软件名称: %s,软件版本: %s" % (app_name, app_version))

data_03 = { "10.11.0.1":
                {"user":"admin", "Port":22},
            "10.11.0.2":
                {"user":"jerry", "Port":80},
            "10.11.0.3":
                {"user":"tuna", "Port":90}
            }
for ip, info in data_03.items():
    print("ssh %s@%s -p %d" % (info.get("user"), ip, info.get("Port")))



















